<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>颜色选择器 - 在线工具集合</title>
    <script src="../utils/toast.js"></script>
    <link rel="stylesheet" href="../utils/styles.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
            min-height: 100vh;
            color: #fff;
            position: relative;
            overflow-x: hidden;
        }

        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.1) 0%, transparent 50%);
            pointer-events: none;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 40px 20px;
            position: relative;
            z-index: 1;
        }

        .header {
            text-align: center;
            margin-bottom: 40px;
        }

        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
            background: linear-gradient(45deg, #00ff88, #00b4d8);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .header p {
            color: rgba(255, 255, 255, 0.8);
            font-size: 1.1em;
        }

        .color-picker-section {
            background: rgba(255, 255, 255, 0.05);
            padding: 40px;
            border-radius: 24px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
        }

        .color-picker-section:hover {
            background: rgba(255, 255, 255, 0.08);
            border-color: rgba(255, 255, 255, 0.2);
        }

        .color-preview {
            width: 150px;
            height: 150px;
            border-radius: 24px;
            margin: 0 auto 40px;
            cursor: pointer;
            position: relative;
            transition: all 0.3s ease;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
            border: 2px solid rgba(255, 255, 255, 0.1);
        }

        .color-preview:hover {
            transform: scale(1.05) translateY(-5px);
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
            border-color: rgba(255, 255, 255, 0.2);
        }

        .color-preview::after {
            content: '点击选择颜色';
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 0.9em;
            color: rgba(255, 255, 255, 0.8);
            opacity: 0;
            transition: all 0.3s ease;
            background: rgba(0, 0, 0, 0.2);
            padding: 6px 12px;
            border-radius: 20px;
            backdrop-filter: blur(5px);
        }

        .color-preview:hover::after {
            opacity: 1;
            transform: translateX(-50%) translateY(-5px);
        }

        .color-input {
            display: none;
        }

        .color-value-group {
            margin-bottom: 25px;
            background: rgba(255, 255, 255, 0.03);
            padding: 20px;
            border-radius: 16px;
            border: 1px solid rgba(255, 255, 255, 0.05);
            transition: all 0.3s ease;
        }

        .color-value-group:hover {
            background: rgba(255, 255, 255, 0.05);
            border-color: rgba(255, 255, 255, 0.1);
            transform: translateY(-2px);
        }

        .color-value-group label {
            display: block;
            margin-bottom: 10px;
            color: rgba(255, 255, 255, 0.9);
            font-size: 1em;
            font-weight: 500;
            letter-spacing: 0.5px;
        }

        .color-value-group input {
            width: 100%;
            padding: 15px 20px;
            border: none;
            border-radius: 12px;
            background: rgba(255, 255, 255, 0.05);
            color: #fff;
            font-size: 16px;
            transition: all 0.3s ease;
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .color-value-group input:focus {
            outline: none;
            box-shadow: 0 0 20px rgba(0, 255, 136, 0.2);
            background-color: rgba(255, 255, 255, 0.08);
        }

        .color-value-group input::placeholder {
            color: rgba(255, 255, 255, 0.5);
        }

        .color-palette {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
            gap: 15px;
            margin-top: 40px;
            padding: 25px;
            background: rgba(255, 255, 255, 0.03);
            border-radius: 20px;
            border: 1px solid rgba(255, 255, 255, 0.05);
        }

        .palette-color {
            width: 50px;
            height: 50px;
            border-radius: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 2px solid transparent;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .palette-color:hover {
            transform: scale(1.1) translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
        }

        .palette-color.active {
            border-color: #00ff88;
            box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
            transform: scale(1.1);
        }

        .action-buttons {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 15px;
            margin-top: 30px;
        }

        .action-btn {
            padding: 15px 25px;
            border: none;
            border-radius: 12px;
            background: linear-gradient(45deg, #00ff88, #00b4d8);
            color: #1a1a1a;
            font-size: 1em;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 255, 136, 0.2);
            letter-spacing: 0.5px;
        }

        .action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(0, 255, 136, 0.3);
        }

        .back-link {
            display: inline-block;
            margin-bottom: 20px;
            color: #00ff88;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .back-link:hover {
            transform: translateX(-5px);
        }

        @media (max-width: 768px) {
            .container {
                padding: 20px 10px;
            }

            .header h1 {
                font-size: 2em;
            }

            .color-input {
                flex-direction: column;
                align-items: center;
            }

            .action-buttons {
                flex-direction: column;
            }

            .action-btn {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <a href="../index.html" class="back-link">← 返回首页</a>
        
        <div class="header">
            <h1>颜色选择器</h1>
            <p>支持多种颜色格式的转换和复制</p>
        </div>

        <div class="color-picker-section">
            <div class="color-preview" onclick="document.getElementById('colorInput').click()"></div>
            <input type="color" id="colorInput" class="color-input">
            
            <div class="color-value-group">
                <label>HEX</label>
                <input type="text" id="hexValue" placeholder="#000000" readonly>
            </div>
            
            <div class="color-value-group">
                <label>RGB</label>
                <input type="text" id="rgbValue" placeholder="rgb(0, 0, 0)" readonly>
            </div>
            
            <div class="color-value-group">
                <label>HSL</label>
                <input type="text" id="hslValue" placeholder="hsl(0, 0%, 0%)" readonly>
            </div>
            
            <div class="color-value-group">
                <label>CMYK</label>
                <input type="text" id="cmykValue" placeholder="cmyk(0%, 0%, 0%, 100%)" readonly>
            </div>

            <div class="action-buttons">
                <button class="action-btn" onclick="copyColor('hex')">复制 HEX</button>
                <button class="action-btn" onclick="copyColor('rgb')">复制 RGB</button>
                <button class="action-btn" onclick="copyColor('hsl')">复制 HSL</button>
                <button class="action-btn" onclick="copyColor('cmyk')">复制 CMYK</button>
            </div>

            <div class="color-palette">
                <div class="palette-color" style="background-color: #ff0000" onclick="setColor('#ff0000')"></div>
                <div class="palette-color" style="background-color: #00ff00" onclick="setColor('#00ff00')"></div>
                <div class="palette-color" style="background-color: #0000ff" onclick="setColor('#0000ff')"></div>
                <div class="palette-color" style="background-color: #ffff00" onclick="setColor('#ffff00')"></div>
                <div class="palette-color" style="background-color: #ff00ff" onclick="setColor('#ff00ff')"></div>
                <div class="palette-color" style="background-color: #00ffff" onclick="setColor('#00ffff')"></div>
                <div class="palette-color" style="background-color: #ffffff" onclick="setColor('#ffffff')"></div>
                <div class="palette-color" style="background-color: #000000" onclick="setColor('#000000')"></div>
            </div>
        </div>
    </div>

    <script>
        const colorPreview = document.querySelector('.color-preview');
        const colorPicker = document.getElementById('colorInput');
        const hexValue = document.getElementById('hexValue');
        const rgbValue = document.getElementById('rgbValue');
        const hslValue = document.getElementById('hslValue');
        const cmykValue = document.getElementById('cmykValue');

        // 设置颜色
        function setColor(color) {
            // 移除所有调色板颜色的active类
            document.querySelectorAll('.palette-color').forEach(c => c.classList.remove('active'));
            
            // 为当前选中的颜色添加active类
            const selectedColor = document.querySelector(`.palette-color[style*="${color}"]`);
            if (selectedColor) {
                selectedColor.classList.add('active');
            }
            
            // 更新颜色值
            updateColorValues(color);
        }

        // 更新颜色值
        function updateColorValues(color) {
            colorPreview.style.backgroundColor = color;
            hexValue.value = color.toUpperCase();

            // 转换为RGB
            const r = parseInt(color.substr(1,2), 16);
            const g = parseInt(color.substr(3,2), 16);
            const b = parseInt(color.substr(5,2), 16);
            rgbValue.value = `rgb(${r}, ${g}, ${b})`;

            // 转换为HSL
            const hsl = rgbToHsl(r, g, b);
            hslValue.value = `hsl(${Math.round(hsl[0])}, ${Math.round(hsl[1])}%, ${Math.round(hsl[2])}%)`;

            // 转换为CMYK
            const cmyk = rgbToCmyk(r, g, b);
            cmykValue.value = `cmyk(${Math.round(cmyk[0])}%, ${Math.round(cmyk[1])}%, ${Math.round(cmyk[2])}%, ${Math.round(cmyk[3])}%)`;
        }

        // RGB转HSL
        function rgbToHsl(r, g, b) {
            r /= 255;
            g /= 255;
            b /= 255;
            const max = Math.max(r, g, b);
            const min = Math.min(r, g, b);
            let h, s, l = (max + min) / 2;

            if (max === min) {
                h = s = 0;
            } else {
                const d = max - min;
                s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
                switch (max) {
                    case r: h = (g - b) / d + (g < b ? 6 : 0); break;
                    case g: h = (b - r) / d + 2; break;
                    case b: h = (r - g) / d + 4; break;
                }
                h /= 6;
            }

            return [h * 360, s * 100, l * 100];
        }

        // RGB转CMYK
        function rgbToCmyk(r, g, b) {
            r /= 255;
            g /= 255;
            b /= 255;
            const k = 1 - Math.max(r, g, b);
            const c = (1 - r - k) / (1 - k) || 0;
            const m = (1 - g - k) / (1 - k) || 0;
            const y = (1 - b - k) / (1 - k) || 0;
            return [c * 100, m * 100, y * 100, k * 100];
        }

        // 复制颜色值
        function copyColor(format) {
            let value;
            switch (format) {
                case 'hex': value = hexValue.value; break;
                case 'rgb': value = rgbValue.value; break;
                case 'hsl': value = hslValue.value; break;
                case 'cmyk': value = cmykValue.value; break;
            }

            navigator.clipboard.writeText(value).then(() => {
                toast.success(`已复制${format.toUpperCase()}格式`);
            }).catch(() => {
                toast.error('复制失败，请重试');
            });
        }

        // 监听事件
        colorPicker.addEventListener('input', (e) => {
            const color = e.target.value;
            setColor(color);
        });

        // 初始化
        setColor('#FF0000');
    </script>
</body>
</html> 